import React from 'react';
import {createStore} from "redux"

function count(state=0,action){
   switch (action.type){
       case "INCRNMENT":
           return state+1;
        case "DECREMENT":
            return state-1;
        default:
            return state
   }
}
const store=createStore(count)

class App extends React.Component{
  constructor(props){
      super(props)
      this.state={
          count:store.getState()
      }
      store.subscribe(e=>{
          this.setState({
            count:store.getState()
          })
      })
  }
  increment(){
      store.dispatch({type:"INCRNMENT"})
  }
  decrement(){
    store.dispatch({type:"DECREMENT"})
  }
  render(){
   return (
       <div>
       {this.state.count}
       <button onClick={this.increment.bind(this)}>+</button>
       <button onClick={this.decrement.bind(this)}>-</button>
       </div>  
   )
  }
}
export default App;